package com.speedchina.permission.web.api;

import com.speedchina.framework.base.BaseController;
import com.speedchina.framework.base.QueryModel;
import com.speedchina.framework.helper.Assert;
import com.speedchina.framework.model.R;
import com.speedchina.framework.validator.ValidatorHelper;
import com.speedchina.framework.validator.group.AddGroup;
import com.speedchina.framework.validator.group.UpdateGroup;
import com.speedchina.permission.base.constant.SysConstant;
import com.speedchina.permission.base.i18n.I18nService;
import com.speedchina.permission.dao.test.BookDao;
import com.speedchina.permission.domain.test.dto.BookDTO;
import com.speedchina.permission.domain.test.entity.Book;
import com.speedchina.permission.domain.test.po.BookPo;
import com.speedchina.permission.service.test.BookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 测试 Controller[仅作为demo]
 *
 * @author hank
 * @create 2021-04-06 下午3:30
 * @deprecated
 **/
@Api(tags = "测试模块", description = "BOOK 表基础CRUD功能")
@RestController
@RequestMapping("/book")
public class BookController extends BaseController<BookService, Book, BookDTO> {

    @Autowired
    private I18nService i18nService;

    @Autowired
    private BookService bookService;

    @ApiOperation("获取BOOK分页信息集合")
    @GetMapping
    // @RequiresPermissions("test:book:list")
    public R query(Integer pageNo, Integer pageSize, BookPo params) {
        return R.page(bookService.queryPage(new QueryModel<>(pageNo, pageSize, params)));
    }

    @ApiOperation("获取指定ID信息")
    @GetMapping("/get")
    // @RequiresPermissions("test:book:info")
    public R get(BookPo params) {
        return R.data(bookService.get(params));
    }

    @ApiOperation("新增")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "书名", dataType = "String", paramType = "path")
    })
    @PostMapping
    // @RequiresPermissions("test:book:add")
    public R add(@RequestBody BookPo entity) {
        ValidatorHelper.validateEntity(entity, AddGroup.class);
        return R.data(this.saveOrUpdate(entity));
    }

    @ApiOperation("修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataType = "Long", paramType = "path"),
            @ApiImplicitParam(name = "title", value = "书名", dataType = "String", paramType = "path")
    })
    @PutMapping
    // @RequiresPermissions("test:book:update")
    public R update(@RequestBody BookPo entity) {
        ValidatorHelper.validateEntity(entity, UpdateGroup.class);
        return R.data(this.saveOrUpdate(entity));
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/{ids}")
    // @RequiresPermissions("test:book:delete")
    public R delete(@PathVariable("ids") String strIds) {
        return R.data(this.deleteBatch(strIds));
    }

}
